package com.kelvem.saas.workbanch.ontology.carrier.controller;

import com.kelvem.saas.workbanch.core.base.Page;
import com.kelvem.saas.workbanch.core.exception.SaasAssert;
import com.kelvem.saas.workbanch.ontology.carrier.model.LineOfferEntity;
import com.kelvem.saas.workbanch.ontology.carrier.request.LineOfferQueryVo;
import com.kelvem.saas.workbanch.ontology.carrier.service.LineOfferService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 线路报价控制层
 *
 * @author kelvem
 * @version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/lineOffer")
public class LineOfferController {
    
    @Resource
    private LineOfferService lineOfferService;
    
    /**
     * 增加线路报价
     * curl -X POST http://localhost:9090/lineOffer/v1 -H 'Content-Type: application/json' -d '{"id": null, "province": "province", "city": "city", "county": "county", "zhixianZhongJiage": 3, "zhixianQingJiage": 1, "ganxianZhongJiage": 8, "ganxianQingJiage": 3, "zhongzhuanZhongJiage": 5, "zhongzhuanQingJiage": 2, "qibuJiage": 1, "quanchengShixiao": new BigDecimal(55), "hesuanXishu": 8, "qibuZhongliang": 7, "price2050": new BigDecimal(2), "price50100": new BigDecimal(82), "price100150": new BigDecimal(33), "price150200": new BigDecimal(28), "price200250": new BigDecimal(98), "price250300": new BigDecimal(71), "price300350": new BigDecimal(69), "price350400": new BigDecimal(15), "price400450": new BigDecimal(29), "price450500": new BigDecimal(67), "price500550": new BigDecimal(88), "price550600": new BigDecimal(52), "price600650": new BigDecimal(7), "price650700": new BigDecimal(59), "price700750": new BigDecimal(18), "price750800": new BigDecimal(23), "price800850": new BigDecimal(61), "price850900": new BigDecimal(87), "price900950": new BigDecimal(91), "price9501000": new BigDecimal(9), "price1000": new BigDecimal(47), "quhuoWeight": new BigDecimal(5), "quhuo525": new BigDecimal(83), "quhuo2550": new BigDecimal(11), "quhuo50": new BigDecimal(64), "quhuoQibujia": new BigDecimal(31), "optUid": "create_uid", "updateUid": "update_uid", "memo": "memo"}'
     *
     * @param lineOffer 线路报价信息
     * @return Long 主键id
     */
    @PostMapping("/v1")
    public Long add(@RequestBody(required = false) LineOfferEntity lineOffer) {
        SaasAssert.notNull(lineOffer);
        
        log.debug("LineOfferController:add:start, lineOffer=【{}】", lineOffer);
        Long lineOfferId = lineOfferService.addLineOffer(lineOffer);
        log.debug("LineOfferController:add:end, lineOfferId={}", lineOfferId);
        
        return lineOfferId;
    }
    
    /**
     * 修改线路报价
     * curl -X PUT http://localhost:9090/lineOffer/v1 -H 'Content-Type: application/json' -d '{"id": 10000, "province": "province", "city": "city", "county": "county", "zhixianZhongJiage": 3, "zhixianQingJiage": 1, "ganxianZhongJiage": 8, "ganxianQingJiage": 3, "zhongzhuanZhongJiage": 5, "zhongzhuanQingJiage": 2, "qibuJiage": 1, "quanchengShixiao": new BigDecimal(55), "hesuanXishu": 8, "qibuZhongliang": 7, "price2050": new BigDecimal(2), "price50100": new BigDecimal(82), "price100150": new BigDecimal(33), "price150200": new BigDecimal(28), "price200250": new BigDecimal(98), "price250300": new BigDecimal(71), "price300350": new BigDecimal(69), "price350400": new BigDecimal(15), "price400450": new BigDecimal(29), "price450500": new BigDecimal(67), "price500550": new BigDecimal(88), "price550600": new BigDecimal(52), "price600650": new BigDecimal(7), "price650700": new BigDecimal(59), "price700750": new BigDecimal(18), "price750800": new BigDecimal(23), "price800850": new BigDecimal(61), "price850900": new BigDecimal(87), "price900950": new BigDecimal(91), "price9501000": new BigDecimal(9), "price1000": new BigDecimal(47), "quhuoWeight": new BigDecimal(5), "quhuo525": new BigDecimal(83), "quhuo2550": new BigDecimal(11), "quhuo50": new BigDecimal(64), "quhuoQibujia": new BigDecimal(31), "optUid": "create_uid", "updateUid": "update_uid", "memo": "memo"}'
     *
     * @param lineOffer 线路报价信息
     * @return Integer 修改记录数
     */
    @PutMapping("/v1")
    public Integer update(@RequestBody(required = false) LineOfferEntity lineOffer) {
        SaasAssert.notNull(lineOffer);
        
        log.debug("LineOfferController:update:start, lineOffer=【{}】", lineOffer);
        int count = lineOfferService.updateLineOffer(lineOffer);
        log.debug("LineOfferController:update:end, count={}", count);
        
        return count;
    }
    
    /**
     * 删除线路报价
     * curl -X DELETE 'http://localhost:9090/lineOffer/v1/10002'
     *
     * @param lineOfferId 线路报价id
     * @return Integer 删除记录数
     */
    @DeleteMapping("/v1/{lineOfferId}")
    public Integer delete(@PathVariable(required = false) Long lineOfferId) {
        SaasAssert.notNull(lineOfferId);
        
        log.debug("LineOfferController:delete:start, lineOfferId={}", lineOfferId);
        int count = lineOfferService.deleteLineOffer(lineOfferId);
        log.debug("LineOfferController:delete:end, count={}", count);
        
        return count;
    }
    
    /**
     * 查询线路报价分页数据
     * curl -X POST http://localhost:9090/lineOffer/v1/queryPage -H 'Content-Type: application/json' -d '{"id": 10000}'
     *
     * @param lineOfferQueryVo 查询用
     * @return Page<LineOfferEntity> 线路报价分页数据
     */
    @PostMapping("/v1/queryPage")
    public Page<LineOfferEntity> queryPage(@RequestBody(required = false) LineOfferQueryVo lineOfferQueryVo) {
        SaasAssert.notNull(lineOfferQueryVo);
        
        log.debug("LineOfferController:queryPage:start, lineOfferQueryVo=【{}】", lineOfferQueryVo);
        Page<LineOfferEntity> page = lineOfferService.queryLineOfferPage(lineOfferQueryVo);
        log.debug("LineOfferController:queryPage:end, page.count={}", page.getSize());
        
        return page;
    }
    
    /**
     * 根据id查线路报价信息
     * curl -X GET 'http://localhost:9090/lineOffer/v1/10000'
     *
     * @param lineOfferId 线路报价id
     * @return LineOffer 线路报价信息
     */
    @GetMapping("/v1/{lineOfferId}")
    public LineOfferEntity getById(@PathVariable(required = false) Long lineOfferId) {
        SaasAssert.notNull(lineOfferId);
        
        log.debug("LineOfferController:getById:start, lineOfferId={}", lineOfferId);
        LineOfferEntity lineOffer = lineOfferService.getLineOfferById(lineOfferId);
        log.debug("LineOfferController:getById:end, lineOffer=【{}】", lineOffer);
        
        return lineOffer;
    }
    
}
